// Berkas :AnimasiPesawat.java
import java.awt.*;
import java.applet.Applet;

public class TerjunPayung extends Applet
	implements Runnable {
	
	Image payung [] = new Image [12];
	Image gbrSekarang;
	Thread threadAnimasi;
	int posisiX = 10;
	int posisiY = 0;
	int indeksPayung;
	
	public void paint(Graphics g) {
		g.drawImage(gbrSekarang, posisiX, posisiY, this);
	}
	
	public void init() {
		for(int i=0; i<payung.length; i++) {
			String namaBerkas = "payung" +
				new Integer(i+5).toString()+ ".jpg";
			payung[i] = getImage(getCodeBase(), namaBerkas);
		indeksPayung = 0;
		gbrSekarang = payung[indeksPayung];
		}
	}
	
	public void start() {
		threadAnimasi = new Thread(this);
		threadAnimasi.start();
	}
	
	public void run() {
		setBackground(Color.white);
		gerakkanPayung();
	}
	
	void gerakkanPayung() {
		while (true) {
			// -- Tunda sebentar
			try {
				Thread.sleep(400);
			}
			
			catch (InterruptedException i) {
			}
			
			indeksPayung = (indeksPayung + 1) %
							payung.length;
			int selang = getSize().width / (payung.length+1);
			if (indeksPayung == 0)
				posisiY = 0;
			else
				posisiY += selang;
				
			if (indeksPayung == (payung.length -1))
				posisiX = 100;
			else
				posisiX += selang;
				
			gbrSekarang = payung[indeksPayung];
			repaint();
		}
	}
}